<?php
class RedisModle{
	protected $hostInfo = array();
	protected $redisHandle = 0;

	public function __construct($hostInfo = array()){
	   $this->connect($hostInfo);
	}
        public function connect($hostInfo = array(),$pconnect = 0){
	   $this->redisHandle = new Redis();
	   if(!isset($hostInfo['host'])){
	       return;
	   }
	   if($pconnect){
	      $return = $this->redisHandle->pconnect($hostInfo['host'],$hostInfo['port'],$hostInfo['timeout'],$hostInfo['persistent_id'],$hostInfo['retry_interval'],$hostInfo['read_timeout']);
	      if($return == FALSE){
	         echo "Error";
	      }
	      return;
	   }
	   /**
	     主机：字符串。可以是主机，也可以是unix域套接字的路径。从版本5.0.0开始，可以指定架构端口：int，可选
	     超时：浮点值，以秒为单位（可选，默认值为0，表示无限制）
	     保留：如果指定重试间隔，则应为空
	     重试间隔：int，以毫秒为单位的值（可选）
	     读取超时：浮点值，以秒为单位（可选，默认值为0，表示无限制）
	   */
	   $return = $this->redisHandle->connect($hostInfo['host'],$hostInfo['port'],$hostInfo['timeout'],$hostInfo['reserved'],$hostInfo['retry_interval'],$hostInfo['read_timeout']);
	   if($return == FALSE){
	      echo "Error";
	   }
	}
	private function auth($auth){
	   $return = $this->redisHandle->auth($auth);
	   if($return == FALSE){
	     echo "Error";
	   }
	}
	public function getStatusInfo($opt = ''){
	   $return = array();
	   if($opt){
	     $return = $this->redisHandle->info($opt);
	   }
	   $return = $this->redisHandle->info();
	   return $return;
	}
	protected function close(){
	   $this->redisHandle->close();
	}
	public function __destruct(){
	   $this->close();
	   $this->redisHandle = 0;
	   $this->hostInfo = array();
	}
}
